package com.abel.quiz.services.impl;/**
 * Created by abel.lin on 2017/2/7.
 */

import com.abel.quiz.dao.BaseDao;
import com.abel.quiz.services.BaseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @author abel.lin
 * @date_time 2017/2/7 14:44
 * @description
 */
public class BaseServiceImpl<M extends BaseDao<T,C>, T, C> implements BaseService<T,C> {

//    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    public M baseMapper;

    public int countByExample(C example) {
        return baseMapper.countByExample(example);
    }

    @Transactional
    public int deleteByExample(C example) {
        return baseMapper.deleteByExample(example);
    }
    @Transactional
    public int deleteByPrimaryKey(String id) {
        return baseMapper.deleteByPrimaryKey(id);
    }
    @Transactional
    public int insert(T record) {
        return baseMapper.insert(record);
    }
    @Transactional
    public int insertSelective(T record) {
        return baseMapper.insertSelective(record);
    }
    @Transactional
    public int updateByExampleSelective(T record, C example) {
        return baseMapper.updateByExampleSelective(record,example);
    }
    @Transactional
    public int updateByExample(T record, C example) {
        return baseMapper.updateByExample(record,example);
    }
    @Transactional
    public int updateByPrimaryKeySelective(T record) {
        return baseMapper.updateByPrimaryKeySelective(record);
    }
    @Transactional
    public int updateByPrimaryKey(T record) {
        return baseMapper.updateByPrimaryKey(record);
    }

    public List<T> selectByExample(C example) {

        return baseMapper.selectByExample(example);
    }

    public T selectByPrimaryKey(String id) {
        return baseMapper.selectByPrimaryKey(id);
    }

    public PageInfo selectPageByExample(C example, int pageNO, int pageSize) {
        PageHelper.startPage(pageNO,pageSize);
        List<T> list = baseMapper.selectByExample(example);
        PageInfo page = new PageInfo(list);

        return page;
    }
}
